<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>license上传</title>
    <link rel="shortcut icon" href="#"/>
    <link rel="stylesheet" href="./css/license.css">
    <link rel="stylesheet" href="./css/reset.css">
    <link rel="stylesheet" href="./js/layui/css/layui.css">
    <script src="./js/rem.js"></script>
    <script src="./js/jquery-3.2.1.js"></script>
    <script src="./js/layui/layui.js"></script>
</head>
<body>
<div class="uploadLicense">
	<!-- 上传失败模块 -->
	<div class="uploadLicense_error">
		<div class="success_error">
	    	<span>!</span>License有误，请检查后重新上传
    	</div>
	</div>
	<!-- 上传模块 -->
    <div class="uploadLicense_content">
        <div class="license_title">license上传</div>
        <div class="upload_content">
            <div class="layui-upload-drag" id="test10">
			  	<i class="layui-icon"></i>
			  	<p>将文件拖到此处，或<span class="upload_text">点击上传</span></p>
			  	<div class="layui-hide" id="uploadDemoView">
			    	<hr>
			    	<img src="" alt="上传成功后渲染" style="max-width: 196px">
			  	</div>
			</div>
			<div class="upload_btn">
				<button type="button" class="layui-btn"  id="test9">提交</button>
			</div>
        </div>
        <div class="currentSystem" >
        	<div class="license_title">当前系统license</div>
            <div id="licensCurrent">
                <div class="system_item">
                    <div class="item_title">license有效期：</div>
                    <div class="item_content item_time">
                        <span id="startDate"></span>
                        至
                        <span id="endDate"></span>
                    </div>
                </div>
                <div class="system_item">
                    <div class="item_title">mac地址：</div>
                    <div class="item_content" id="macAddres"></div>
                </div>
                <div class="system_item">
                    <div class="item_title">ip地址：</div>
                    <div class="item_content" id="ipAddress"></div>
                </div>
                <div class="system_item">
                    <div class="item_title">用户数：</div>
                    <div class="item_content" id="userNum"></div>
                </div>
                <div class="system_item">
                    <div class="item_title">客户数：</div>
                    <div class="item_content" id="clientNum"></div>
                </div>
            </div>
            <div id="licenseError">
                <div class="system_item">
                    <div class="item_title"></div>
                    <div class="item_content item_time" id="licenseErrorMsg">

                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- 上传成功模块 -->
    <div class="uploadLicense_success">
    	<div class="success_title">
	    	<div class="success_icon"></div>
	    	<div class="success_text">上传成功</div>
    	</div>
    	<div class="currentSystem">
        	<span>!</span>请重启服务器使license生效
        </div>
    </div>
</div>
<script>
    $(function(){
        //加载当前系统license证书信息
        $.ajax({
            type:"get",
            url:"api/license/getCertificateInfo",
            dataType:"json",
            success:function(data){
                    $('#startDate').html(data.notBefore)
                    $('#endDate').html(data.notAfter)
                    var macStr="",ipStr="",macArray=data.macAddress,ipArray=data.ipAddress
                    macArray.forEach(function(item){
                        macStr+=item+";"
                    })
                    ipArray.forEach(function(item){
                        ipStr+=item+";"
                    })
                    $('#macAddres').html(macStr)
                    $('#ipAddress').html(ipStr)
                    $('#userNum').html(data.userNum)
                    $('#clientNum').html(data.clientNum)
            },
            error:(data)=>{
                $('#licenseErrorMsg').html("当前系统未安装证书")
            },
        })
    })
    var ctxPath = "http://www.kangxijiankang.com/bcps";

    // 获取当前日期
    var myDate = new Date(),timer;
    let currentDate = myDate.getFullYear() + '-' + (myDate.getMonth()+1) + '-' + myDate.getDate();

    // 定义搜索条件的值
    let selectDate = currentDate,contentdata = '-1';

	// 文件上传处理
    layui.use(['upload'], function(){
    	upload = layui.upload;
        //拖拽上传
		upload.render({
		    elem: '#test10',
		    accept: 'file',
		    url: 'api/license/uploadFiles', //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
		    auto: false,
		    bindAction: '#test9',
		    done: function(res){
				let time = 5;
		      	timer = setInterval(function(){
					if(time == 1){
						clearInterval(timer);
						$('.uploadLicense_content').css('display','none');
		      			$('.uploadLicense_success').css('display','block');
					}else {
						time -= 1;
						$('#test9').html('上传中（'+time+'s）');
					}
		      	},1000)
		    },
		    error: function(res){
				$('.uploadLicense_error').css('display','block');
		    }
		});
    });

</script>
</body>
</html>
